import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-01-13
 * Time: 18:34
 */
public class test1 {
    /*
    LeetCode 290 单词规律
     */
    public boolean wordPattern(String pp, String ss) {
        char[] p = pp.toCharArray();
        String[] s = ss.split(" ");
        if(p.length!=s.length){
            return false;
        }
        String[] ret = new String[26];
        Map<String,Integer> hash1 = new HashMap<>();
        for(int i=0;i<p.length;i++){
            int a = p[i]-'a';
            if(ret[a]==null){
                ret[a]=s[i];
            }else if(!ret[a].equals(s[i])){
                return false;
            }
            if(!hash1.containsKey(s[i])){
                hash1.put(s[i],a);
            }else if(hash1.get(s[i])!=a){
                return false;
            }
        }
        return true;
    }
}
